home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Graphics / Utility / ARTAbrot 1.1 / Main_ARTAbrot.c < prev    next >
C/C++ Source or Header  |  1993-11-22  |  24KB  |  649 lines

  1. /* Main_ARTAbrot */
  2.  
  3. /* Program name:  Main_ARTAbrot   
  4.  Function:  This is the main module for this program.  
  5. History: 8/18/93 Original by George Warner
  6.    */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. #include "ComUtil_ARTAbrot.h"    /* Common */
  12.  
  13. #include "AB_Alert.h"    /* Alert */
  14. #include "About_ARTAbrot.h"    /* Modeless Dialog */
  15. #include "BrotCode.h"
  16. #include "Enter_Coordinates.h"    /* Modeless Dialog */
  17. #include "ARTAbrot.h"    /* Window */
  18. #include "Menu_ARTAbrot.h"    /* Menus */
  19.  
  20. Boolean        DoIt;                                /* Flag saying an event is ready */
  21. short        code;                                    /* Determine event type */
  22. WindowPtr    whichWindow;                            /* See which window for event */
  23. long        mResult;                                /* Menu list and item selected values */
  24. short        theMenu,theItem;                        /* Menu list and item selected */
  25. Boolean        Is_A_Dialog;                        /* Flag for modless dialogs */
  26. short        charCode, itemHit;                    /* For modeless dialogs*/
  27. char        ch;                                    /* Key pressed in Ascii */
  28. Boolean        DoTheModelessEvent, CmdDown;        /* For modeless dialogs*/
  29. WindowPeek    thePeeked;                            /* For modeless dialogs*/
  30.  
  31. extern int processing_brot;
  32.  
  33. /* Handle key strokes */
  34. static void DoKeyEvent(void);
  35.  
  36. /* Handle a diskette inserted */
  37. static void DoDiskEvent(void);
  38.  
  39. /* Handle a window being resized */
  40. static void DoGrow(WindowPtr whichWindow);
  41.  
  42. /* Handle a window being dragged */
  43. static void DoDrag(WindowPtr whichWindow);
  44.  
  45. /* Handle a window goaway box */
  46. static void DoGoAway(WindowPtr whichWindow);
  47.  
  48. /* Handle an update to the window */
  49. static void DoUpdate(void);
  50.  
  51.  
  52. /* MAIN entry point */
  53. void main(void);
  54.  
  55. /* Handle the OS event */
  56. void DoOSEvent(EventRecord *myEvent);
  57.  
  58.  
  59. /* Routine: DoOSEvent */
  60. /* Purpose: Handle DoOSEvents */
  61.  
  62. void DoOSEvent(EventRecord *myEvent)
  63. {
  64.  
  65. if (((myEvent->message & osEvtMessageMask) >> 24) == suspendResumeMessage)/*  See which  */
  66.     {
  67.     if ((myEvent->message & resumeFlag) == 0)        /* Suspend */
  68.         {
  69.         InTheForeground = FALSE;
  70.         }
  71.     else
  72.         {
  73.         InTheForeground = TRUE;
  74.         }                                        /* End of IF */
  75.     }                                            /* End of IF */
  76. }
  77.  
  78. /* ======================================================= */
  79.  
  80. /* ======================================================= */
  81.  
  82. /* Routine: WNEIsImplemented */
  83. /* Purpose: See if the MultiFinder trap, WaitNextEvent, is available */
  84.  
  85. Boolean IsWNEIsImplemented()                /* See if WaitNextEvent is available */
  86. {
  87. #define    WNETrapNumber    0xA860                /* The expected trap number */
  88. #define    kGestaltTrapID    0xA1AD                /* The expected trap number */
  89.  
  90. SysEnvRec    theWorld;                        /* Environment record */
  91. OSErr    discardError;                        /* Error code returned */
  92. Boolean    theWNEIsImplemented;                /* Value to return */
  93. long    result;                                /* Value returned */
  94.  
  95.     Black_ForeColor.red = 0x0000;  Black_ForeColor.green = 0x0000;    Black_ForeColor.blue = 0x0000;  /* Get black color */
  96.     White_BackColor.red = 0xFFFF;  White_BackColor.green = 0xFFFF;  White_BackColor.blue = 0xFFFF;  /* Get white color */
  97.  
  98.     HasColorQD = FALSE;                        /* Init to no color QuickDraw */
  99.     HasFPU = FALSE;                            /* Init to no floating point chip */
  100.     HasAppleEvents = FALSE;                    /* Whether AppleEvents are available */
  101.     HasAliasMgr = FALSE;                    /* Whether AliasMgr is available */
  102.     HasEditionMgr = FALSE;                    /* Whether EditionMgr is available */
  103.     HasGestalt = FALSE;                        /* Whether Gestalt is available */
  104.     HasNewStdFile = FALSE;                    /* Whether HasNewStdFile is available */
  105.     HasPPCToolbox = FALSE;                    /* Whether PPCToolbox is available */
  106.     Has32BitQuickDraw = FALSE;                /* Whether 32Bit QuickDraw is available */
  107.     InTheForeground = TRUE;                    /* Init to a foreground app */
  108.     discardError = SysEnvirons(1, &theWorld);    /* Check how old this system is */
  109.     if (theWorld.machineType < 0) {            /* Negative means really old */
  110.         theWNEIsImplemented = FALSE;        /* Really old ROMs, no WNE possible */
  111.     }
  112.     else {
  113.         theWNEIsImplemented = CheckTrapAvailable(WNETrapNumber, ToolTrap);/* See if trap is there */
  114.         HasColorQD = theWorld.hasColorQD;    /* Flag for Color QuickDraw being available */
  115.         HasFPU = theWorld.hasFPU;            /* Flag for Floating Point Math Chip being available */
  116.         HasGestalt = CheckTrapAvailable(kGestaltTrapID, ToolTrap);    /* Whether Gestalt is available */
  117.         if (HasGestalt) {                    /* Do if Gestalt is available */
  118.             discardError = Gestalt(gestaltAliasMgrAttr,&result);
  119.             if ((discardError == 0) && ((result & (0x00000001 << gestaltAliasMgrPresent)) != 0))
  120.                 HasAliasMgr = TRUE;
  121.  
  122.             discardError = Gestalt(gestaltEditionMgrAttr,&result);
  123.             if ((discardError == 0) && ((result & (0x00000001 << gestaltEditionMgrPresent)) != 0))
  124.                 HasEditionMgr = TRUE;
  125.  
  126.             discardError = Gestalt(gestaltAppleEventsAttr,&result);
  127.             if ((discardError == 0) && ((result & (0x00000001 << gestaltAppleEventsPresent)) != 0))
  128.                 HasAppleEvents = TRUE;
  129.  
  130.             discardError = Gestalt(gestaltPPCToolboxAttr,&result);
  131.             if ((discardError == 0) && ((result & (0x00000001 << gestaltPPCToolboxPresent)) != 0))
  132.                 HasPPCToolbox = TRUE;
  133.  
  134.             discardError = Gestalt(gestaltQuickdrawVersion,&result);
  135.             if ((discardError == 0) && ((result & gestalt32BitQD) != 0))
  136.                 Has32BitQuickDraw = TRUE;
  137.  
  138.             discardError = Gestalt(gestaltStandardFileAttr,&result);
  139.             if ((discardError == 0) && ((result & (0x00000001 << gestaltStandardFile58)) != 0))
  140.                 HasNewStdFile = TRUE;
  141.         }
  142.     }
  143.     return(theWNEIsImplemented);
  144. }
  145.  
  146. /* ======================================================= */
  147.  
  148. /* Routine: Handle_User_Event */
  149. /* Purpose: Check for user events */
  150.  
  151. void Handle_User_Event()                            /* Check for user events */
  152. {
  153. UserEventRec    TheUserEvent;                        /* The user event */
  154.  
  155. GetUserEvent(&TheUserEvent);                        /* Check for any user events */
  156. if (TheUserEvent.ID != UserEvent_None)                /* Only do if we have any */
  157.     {
  158.  
  159.     switch (TheUserEvent.ID)                        /* Key off the Event ID */
  160.         {
  161.         case UserEvent_Open_Window:             /* Open a Window or Modeless dialog */
  162.             switch (TheUserEvent.ID2)                /* Do the appropiate window */
  163.                 {
  164.                 case Res_W_ARTAbrot: 
  165.                     Open_ARTAbrot();        /* Open this window */
  166.                     break;
  167.                 case Res_MD_About_ARTAbrot:
  168.                     Open_About_ARTAbrot();/* Open this modeless dialog */
  169.                     break;
  170.                 case Res_MD_Enter_Coordinat:
  171.                     Open_Enter_Coordinat();/* Open this modeless dialog */
  172.                     break;
  173.                 default:                        /* Handle others */
  174.                     break;
  175.                 }                                /* End of the switch */
  176.             break;
  177.  
  178.         case UserEvent_Close_Window:             /* Close a Window or Modeless dialog */
  179.             switch (TheUserEvent.ID2) {            /* Do the appropiate window */
  180.                 case Res_W_ARTAbrot:
  181.                     Close_ARTAbrot(WPtr_ARTAbrot);/* Close this window */
  182.                     break;
  183.                 case Res_MD_About_ARTAbrot:
  184.                     Close_About_ARTAbrot(WPtr_About_ARTAbrot);/* Close this modeless dialog */
  185.                     break;
  186.                 case Res_MD_Enter_Coordinat:
  187.                     Close_Enter_Coordinat(WPtr_Enter_Coordinat);/* Close this modeless dialog */
  188.                     break;
  189.                 default:                        /* Handle others */
  190.                     break;
  191.                 }                                /* End of the switch */
  192.  
  193.             break;
  194.         default:                                /* Not standard, must be program specific */
  195.             break;
  196.         }                                        /* End of switch */
  197.     }                                            /* End of IF */
  198. }
  199.  
  200. /* ======================================================= */
  201.  
  202. /* Routine: DoKeyEvent */
  203. /* Purpose: Handle a key pressed */
  204.  
  205. static void DoKeyEvent()                            /* Handle key presses */
  206. {
  207. short    charCode;                                    /* Key code */
  208. char    ch;                                        /* Key pressed in Ascii */
  209. long    mResult;                                    /* Menu list and item, if a command key */
  210. short    theMenu,theItem;                            /* Menu list and item, if command key */
  211.  
  212.     charCode = myEvent.message & charCodeMask;        /* Get the character */
  213.     ch = (char)charCode;                            /* Change it to ASCII */
  214.     
  215.     if ((myEvent.modifiers & cmdKey) != 0) {        /* See if Command key is down */
  216.         mResult = MenuKey(ch);                        /* See if a menu selection */
  217.         theMenu = HiWord(mResult);                    /* Get the menu list number */
  218.         theItem = LoWord(mResult);                    /* Get the menu item number */
  219.         if (theMenu != 0)                            /* See if a list was selected */
  220.             Handle_My_Menu(theMenu, theItem);        /* Do the menu selection */
  221.     
  222.         if (((ch == 'x') || (ch == 'X')) && (theInput != NIL))/* See if a standard Cut */
  223.             TECut(theInput);                        /* Handle a Cut in a TE area */
  224.         if (((ch == 'c') || (ch == 'C')) && (theInput != NIL))/* See if a standard Copy */
  225.             TECopy(theInput);                        /* Handle a Copy in a TE area */
  226.         if (((ch == 'v')  ||  (ch == 'V')) && (theInput != NIL))/* See if a standard Paste */
  227.             TEPaste(theInput);                        /* Handle a Paste in a TE area */
  228.         if ((ch = '.') && (processing_brot)) {
  229.             finish_brot();
  230.         }
  231.     }
  232.     else if (theInput != NIL)
  233.         TEKey(ch,theInput);                        /* Place the normal key stroke */
  234.  
  235. }
  236.  
  237. /* ======================================================= */
  238.  
  239. /* Routine: DoDiskEvent */
  240. /* Purpose: Handle a diskette inserted */
  241.  
  242. static void DoDiskEvent()                            /* Handle disk inserted */
  243. {
  244. short    theError;                                    /* Error returned from mount */
  245.  
  246. if (HiWord(myEvent.message) != noErr)                /* See if a diskette mount error */
  247.     {
  248.     myEvent.where.h = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left) / 2) - (304 / 2);/* Center horz */
  249.     myEvent.where.v = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) / 3) - (104 / 2);/* Top 3ed vertically */
  250.     InitCursor();                                    /* Make sure it has an arrow cursor */
  251.     theError = DIBadMount(myEvent.where, myEvent.message);/* Let the OS handle the diskette */
  252.     }                                            /* End of IF */
  253.  
  254. }
  255.  
  256. /* ======================================================= */
  257.  
  258. /* Routine: DoGrow */
  259. /* Purpose: Handle a window resize */
  260.  
  261. static void DoGrow(WindowPtr whichWindow)
  262. {
  263. Rect    OldRect;                                    /* Window rect before the grow */
  264. Point    myPt;                                        /* Point for tracking grow box */
  265. Rect    GrowRect;                                    /* Set the grow bounds */
  266. long    mResult;                                    /* Result from the grow */
  267. long    theRefCon;                                    /* Refcon with layer masked off */
  268.  
  269. if (!Doing_MovableModal)                            /* Select proper window */
  270.     {
  271.     if (whichWindow != nil)                        /* See if we have a legal window */
  272.         {
  273.         SetPort(whichWindow);                        /* Get ready to draw in this window */
  274.  
  275.         myPt = myEvent.where;                        /* Get mouse position */
  276.         GlobalToLocal(&myPt);                        /* Make it relative */
  277.  
  278.         OldRect = whichWindow->portRect;            /* Save the rect before resizing */
  279.  
  280.  
  281.         theRefCon = GetWRefCon(whichWindow);        /* Get the refcon */
  282.         switch (theRefCon) {                            /* Do the appropriate window */
  283.             case Res_W_ARTAbrot:
  284.                 /* Don't allow resize if we're running. */
  285.                 if (!processing_brot) {
  286. //                    SetRect(&GrowRect, 4, 4, (qd.screenBits.bounds.right - qd.screenBits.bounds.left)-4,  (qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - 4);/* l,t,r,b */
  287.                     SetRect(&GrowRect, 4, 4, (1280)-4,  (qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - 4);/* l,t,r,b */
  288.                     mResult = GrowWindow(whichWindow, myEvent.where, &GrowRect);/* Grow it */
  289.                     SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), true);/* Resize to result */
  290.                     Resized_ARTAbrot(whichWindow);    /* Resized this window */
  291.                 }
  292.                 break;
  293.             default:                            /* allow other buttons, trap for debug */
  294.                 SetRect(&GrowRect, 4, 4, (qd.screenBits.bounds.right - qd.screenBits.bounds.left)-4,  (qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - 4);/* l,t,r,b */
  295.                 mResult = GrowWindow(whichWindow, myEvent.where, &GrowRect);/* Grow it */
  296.                 SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), true);/* Resize to result */
  297.                 break;
  298.         }
  299.  
  300.         SetPort(whichWindow);                        /* Get ready to draw in this window */
  301.  
  302.         myPt.h = whichWindow->portRect.right - whichWindow->portRect.left;/* Local right edge */
  303.         myPt.v = whichWindow->portRect.bottom - whichWindow->portRect.top;/* Local bottom edge */
  304.  
  305.         SetRect(&GrowRect, 0, OldRect.bottom - 15, OldRect.right + 15, OldRect.bottom + 15);/* Position for horz scrollbar area */
  306.         EraseRect(&GrowRect);                        /* Erase old area */
  307.         InvalRect(&GrowRect);                        /* Flag us to update it */
  308.  
  309.         SetRect(&GrowRect, OldRect.right - 15, 0, OldRect.right + 15, OldRect.bottom + 15);/* Position for vert scrollbar area */
  310.         EraseRect(&GrowRect);                        /* Erase old area */
  311.         InvalRect(&GrowRect);                        /* Flag us to update it */
  312.  
  313.         DrawGrowIcon(whichWindow);                    /* Draw the grow Icon again */
  314.         }                                        /* End of IF */
  315.     }                                            /* End of IF */
  316. }
  317.  
  318.  
  319.  
  320. /* Routine: DoDrag */
  321. /* Purpose: Drag a window around */
  322.  
  323. static void DoDrag(WindowPtr whichWindow)
  324. {
  325. Rect    OldRect;                            /* Window rect before the drag */
  326. Rect    tempRect;                            /* temporary rect */
  327. long    theRefCon;                            /* Refcon with layer masked off */
  328.  
  329.     if ((!Doing_MovableModal) || (Doing_MovableModal && (whichWindow == FrontWindow()))) {    /* See if OK to drag */
  330.         OldRect = whichWindow->portRect;    /* Save the rect before resizing */
  331.  
  332.         tempRect = qd.screenBits.bounds;    /* Get screen area,  l,t,r,b, drag area */
  333.         SetRect(&tempRect,tempRect.left+4,tempRect.top+4,tempRect.right-4,tempRect.bottom - 4);
  334.         DragWindow(whichWindow, myEvent.where, &tempRect);    /* Drag the window */
  335.  
  336.         theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  337.         switch (theRefCon) {                /* Do the appropiate window */
  338.             case Res_W_ARTAbrot:
  339.                 Moved_ARTAbrot(whichWindow);    /* Moved this window */
  340.                 break;
  341.             case Res_MD_About_ARTAbrot:
  342.                 Moved_About_ARTAbrot(whichWindow);    /* Moved this modeless dialog */
  343.                 break;
  344.             case Res_MD_Enter_Coordinat:
  345.                 Moved_Enter_Coordinat(whichWindow);    /* Moved this modeless dialog */
  346.                 break;
  347.             default:                        /* allow other buttons, trap for debug */
  348.                 break;    
  349.         }    
  350.     }    
  351. }
  352.  
  353.  
  354.  
  355. /* Routine: DoGoAway */
  356. /* Purpose: Close a window */
  357.  
  358. static void DoGoAway(WindowPtr whichWindow)
  359. {
  360. long    theRefCon;                                    /* Refcon with layer masked off */
  361.  
  362.     if (!Doing_MovableModal) {                            /* Select proper window */
  363.         if (TrackGoAway(whichWindow,myEvent.where)) {    /* See if mouse released in GoAway box */
  364.             theRefCon = GetWRefCon(whichWindow);        /* Get the refcon */
  365.             switch (theRefCon) {                            /* Do the appropiate window */
  366.                 case Res_W_ARTAbrot:
  367.                     Close_ARTAbrot(whichWindow);        /* Close this window */
  368.                     break;
  369.                 case Res_MD_About_ARTAbrot:
  370.                     Close_About_ARTAbrot(whichWindow);/* Close this modeless dialog */
  371.                     break;
  372.                 case Res_MD_Enter_Coordinat:
  373.                     Close_Enter_Coordinat(whichWindow);/* Close this modeless dialog */
  374.                     break;
  375.                 default:                            /* allow other buttons, trap for debug */
  376.                     break;    
  377.             }    
  378.         }    
  379.     }    
  380. }
  381.  
  382.  
  383.  
  384. /* Routine: DoInContent */
  385. /* Purpose: Pressed in the content area */
  386.  
  387. static void DoInContent(WindowPtr whichWindow,EventRecord *myEvent)
  388. {
  389. long    theRefCon;                            /* Refcon with layer masked off */
  390.  
  391.     if (!Doing_MovableModal) {                /* Select proper window */
  392.         if (whichWindow != FrontWindow()) {    /* See if already selected or not, in front if selected */
  393.             SelectWindow(whichWindow);        /* Select this window to make it active */
  394.         }
  395.         else {
  396.             SetPort(whichWindow);            /* Get ready to draw in this window */
  397.             theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  398.             switch (theRefCon) {            /* Do the appropiate window */
  399.                 case Res_W_ARTAbrot:
  400.                     Do_ARTAbrot(myEvent);    /* Handle this window */
  401.                     break;
  402.                 default:                    /* allow other buttons, trap for debug */
  403.                     break;
  404.             }
  405.         }
  406.     }
  407. }
  408.  
  409.  
  410.  
  411. /* Routine: DoUpdate */
  412. /* Purpose: Got an update event */
  413.  
  414. static void DoUpdate()
  415. {
  416. WindowPtr    whichWindow;                    /* See which window for event */
  417. long    theRefCon;                            /* Refcon with layer masked off */
  418.  
  419.     whichWindow = (WindowPtr)myEvent.message;    /* Get the window the update is for */
  420.  
  421.     BeginUpdate(whichWindow);                /* Set the clipping to the update area */
  422.     theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  423.     switch (theRefCon) {                    /* Do the appropiate window */
  424.         case Res_W_ARTAbrot:
  425.             Update_ARTAbrot(whichWindow);    /* Update this window */
  426.             break;
  427.         default:                            /* allow other buttons, trap for debug */
  428.             break;
  429.     }
  430.     EndUpdate(whichWindow);                    /* Return to normal clipping area */
  431. }
  432.  
  433.  
  434.  
  435. /* Routine: DoActivate */
  436. /* Purpose: Got an activate or deactivate event */
  437.  
  438. void DoActivate()
  439. {
  440. WindowPtr    whichWindow;                /* See which window for event */
  441. Boolean    Do_An_Activate;                    /* Flag to pass */
  442. long    theRefCon;                        /* Refcon with layer masked off */
  443.  
  444.     whichWindow = (WindowPtr)myEvent.message;    /* Get the window the update is for */
  445.  
  446.     Do_An_Activate =  ((myEvent.modifiers & 0x0001) != 0);    /* Make sure it is Activate and not DeActivate */
  447.     theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  448.     switch (theRefCon) {                /* Do the appropiate window */
  449.         case Res_W_ARTAbrot:
  450.             Activate_ARTAbrot(whichWindow,Do_An_Activate);    /* Activate or deactivate this window */
  451.             break;
  452.         default:                        /* allow other buttons, trap for debug */
  453.             break;
  454.     }
  455. }
  456.  
  457.  
  458.  
  459. void main()
  460. {
  461. char tmp_string[256];
  462.  
  463.     MoreMasters();                        /* This reserves space for more handles */
  464.     MaxApplZone();                        /* Give us room for memory allocation */
  465.     InitGraf((Ptr) &qd.thePort);        /* Quickdraw Init */
  466.     InitFonts();                        /* Font manager init */
  467.     InitWindows();                        /* Window manager init */
  468.     InitMenus();                        /* Menu manager init */
  469.     TEInit();                            /* Text edit init */
  470.     InitDialogs(nil);                    /* Dialog manager */
  471.  
  472.     FlushEvents(everyEvent , 0);        /* Clear out all events */
  473.     InitCursor();                        /* Make an arrow cursor */
  474.  
  475.     doneFlag = FALSE;                    /* Do not exit program yet */
  476.  
  477.     Init_My_Menus();                    /* Initialize menu bar */
  478.  
  479.     theInput = nil;                        /* Init to no text edit selection active */
  480.  
  481.     SleepValue = 0;                        /* Set sleep value */
  482.     WNE = IsWNEIsImplemented();            /* See if WaitNextEvent is available */
  483.  
  484.     /* We need certain minimum conditions.  We'll check here. */
  485.     if (!HasGestalt) {
  486.         sprintf(tmp_string, "Sorry, Gestalt required for this program.");
  487.         AB_Alert(tmp_string);
  488.         doneFlag = TRUE;                /* Exit program. */
  489.     }
  490.     else {
  491.         if (!HasColorQD) {
  492.             sprintf(tmp_string, "Sorry, Color Quickdraw required for this program.");
  493.             AB_Alert(tmp_string);
  494.             doneFlag = TRUE;            /* Exit program. */
  495.         }
  496.     }
  497.  
  498.     UserEventList = nil;                /* No user events yet */
  499.  
  500.     cursorRgn = NewRgn();                /* Cursor region for WaitNextEvent */
  501.  
  502.     Init_ARTAbrot();                    /* Initialize the window routines */
  503.     Init_About_ARTAbrot();                /* Initialize the modeless dialog routines */
  504.     I_A_Alert();                        /* Initialize the alert globals */
  505.     Init_Enter_Coordinat();                /* Initialize the modeless dialog routines */
  506.     Doing_MovableModal = false;            /* Not currently doing a movable modal */
  507.  
  508.  
  509.     do {
  510.         if (processing_brot)
  511.             continue_brot();            /* See if we can get a line of Mandelbrot. */
  512.         Handle_User_Event();            /* Check for user events */
  513.         if (theInput != NIL) {            /* See if a TE is active */
  514.             TEIdle(theInput);            /* Blink the cursor if everything is ok */
  515.         }
  516.         if (WNE) {                        /* See if do the MultiFinder way */
  517.             DoIt = WaitNextEvent(everyEvent, &myEvent, SleepValue, cursorRgn);/* Wait for an event */
  518.         }
  519.         else {
  520.             SystemTask();                /* For support of desk accessories */
  521.             DoIt = GetNextEvent(everyEvent, &myEvent);/* See if an event is ready */
  522.         }
  523.  
  524.         if (DoIt) {                        /* If event then... */
  525.             Is_A_Dialog = IsDialogEvent(&myEvent);    /* See if a modeless dialog event */
  526.             if (Is_A_Dialog == TRUE) {                /* Handle a dialog event */
  527.                 if (myEvent.what == updateEvt) {    /* Handle the update of a Modeless Dialog */
  528.                     whichWindow = (WindowPtr)myEvent.message; /* Get the window the update is for */
  529.                     BeginUpdate(whichWindow);        /* Set update clipping area */
  530.                     Update_About_ARTAbrot(whichWindow);    /* Update the modeless dialog */
  531.                     Update_Enter_Coordinat(whichWindow);/* Update the modeless dialog */
  532.                     EndUpdate(whichWindow);            /* Return to normal clipping area */
  533.                 }
  534.                 else {
  535.                     DoTheModelessEvent = TRUE;        /* Go ahead and do it so far */
  536.  
  537.                     if (myEvent.what == keyDown) {     /* Check the key down, for a command key event */
  538.                         CmdDown = ((myEvent.modifiers / cmdKey) & 1);/* Get the command key state */
  539.                         charCode = myEvent.message & charCodeMask;/* Get the character */
  540.                         ch = (char)charCode;        /* Change it to ASCII */
  541.  
  542.                         if ((charCode == 13) || (charCode == 0x03))/* CR or Enter */
  543.                             DoTheModelessEvent = TRUE;/* Handle the default selection */
  544.  
  545.                         if (CmdDown != 0) {            /* Handle if the command key was down */
  546.                             mResult = MenuKey(ch);    /* See if a menu selection */
  547.                             theMenu = HiWord(mResult);    /* Get the menu list number */
  548.                             theItem = LoWord(mResult);    /* Get the menu item number */
  549.                             if (theMenu != 0)          /* See if a list was selected */
  550.                                 Handle_My_Menu(theMenu, theItem); /* Do the menu selection */
  551.  
  552.                             whichWindow = FrontWindow(); /* Get the front window */
  553.                             if ((ch == 'x') || (ch == 'X'))    /* Handle a CUT */
  554.                                 DlgCut(whichWindow);/* Do the dialog cut */
  555.                             if ((ch == 'c') || (ch == 'C'))    /* Handle a COPY */
  556.                                 DlgCopy(whichWindow);/* Do the dialog copy */
  557.                             if ((ch == 'v') || (ch == 'V'))    /* Handle a PASTE */
  558.                                 DlgPaste(whichWindow);    /* Do the dialog paste */
  559.  
  560.                             DoTheModelessEvent = FALSE;/* We handled the command key */
  561.                         }
  562.                     }
  563.  
  564.                     if (DoTheModelessEvent == TRUE) {     /* Do we handle it? */
  565.                         if ((DialogSelect(&myEvent, &whichWindow, &itemHit)) || (myEvent.what == mouseDown) || (myEvent.what == keyDown)) { /* Ck if do it */
  566.                             Do_About_ARTAbrot(&myEvent,whichWindow,itemHit);    /* Handle the Modeless Dialog */
  567.                             Do_Enter_Coordinat(&myEvent,whichWindow,itemHit);    /* Handle the Modeless Dialog */
  568.                         }
  569.                     }
  570.                 }
  571.             }
  572.             else {
  573.                 switch (myEvent.what) {        /* Decide type of event */
  574.                     case mouseDown :        /* Mouse button pressed */
  575.                         code = FindWindow(myEvent.where, &whichWindow);/* Get which window the event happened in */
  576.  
  577.                         switch (code) {        /* Decide type of event again */
  578.                             case inMenuBar:    /* In the menubar */
  579.                                 mResult = MenuSelect(myEvent.where);    /* Do menu selection */
  580.                                 theMenu = HiWord(mResult);    /* Get the menu list number */
  581.                                 theItem = LoWord(mResult);    /* Get the menu list item number */
  582.                                 Handle_My_Menu( theMenu, theItem);    /* Handle the menu */
  583.                                 break;
  584.  
  585.                             case inDrag:    /* In window drag area */
  586.                                 DoDrag(whichWindow);    /* Go drag the window */
  587.                                 break;
  588.  
  589.                             case inGrow:    /* In window grow area */
  590.                                 DoGrow(whichWindow);    /* Handle the growing */
  591.                                 break;
  592.  
  593.                             case inGoAway:    /* In window goaway area */
  594.                                 DoGoAway(whichWindow);    /* Handle the goaway button */
  595.                                 break;
  596.  
  597.                             case inContent:    /* In window  contents */
  598.                                 DoInContent(whichWindow,&myEvent);    /* Handle the hit inside a window */
  599.                                 break;
  600.  
  601.                             case inSysWindow:    /* See if a DA selectio */
  602.                                 SystemClick(&myEvent, whichWindow);    /* Let other programs in */
  603.                                 break;
  604.  
  605.                             default:        /* Handle others */
  606.                                 break;
  607.                         }
  608.                         break;                /* End of MouseDown */
  609.  
  610.                     case keyDown:            /* Handle key inputs */
  611.                     case autoKey:            /* and auto repeats */
  612.                         DoKeyEvent();        /* Get the key and handle it */
  613.                         break;
  614.  
  615.                     case updateEvt:            /* Update event for a window */
  616.                         DoUpdate();            /* Handle the update */
  617.                         break;
  618.  
  619.                     case diskEvt:            /* Disk inserted event */
  620.                         DoDiskEvent();        /* Handle a disk event */
  621.                         break;
  622.  
  623.                     case activateEvt:        /* Window activated event */
  624.                         DoActivate();        /* Handle the activation */
  625.                         break;
  626.  
  627.                     case osEvt:                /* OS event */
  628.                         DoOSEvent(&myEvent);    /* Handle the activation */
  629.                         break;                    /* End of osEvt */
  630.  
  631.                     default:                /* Used for debugging, to see what other events are coming in */
  632.                         break;
  633.                 }
  634.             }
  635.         }
  636.         else {
  637.             whichWindow = FrontWindow();    /* Get the current front window */
  638.             if (whichWindow != NIL) {        /* See if we have a window */
  639.                 thePeeked = (WindowPeek)whichWindow;    /* Peek inside, look for dialog */
  640.                 if (thePeeked->windowKind == dialogKind) {    /* DialogSelect will crash if no dialogs */
  641.                     if (DialogSelect(&myEvent, &whichWindow, &itemHit)) { /* Blink cursor in modeless TEs */
  642.                     }
  643.                 }
  644.             }
  645.         }
  646.     }
  647.     while (doneFlag == FALSE);                /* End of the event loop */
  648. }                                            /* end of main */
  649.